{{extends file = '../../layout.html'}}
{{block name = content}}
<div class="row">
    <div class="col-xs-12">
        <h3 class="header smaller lighter blue">评论列表</h3>
        <span class="btn btn-info btn-sm tooltip-info delete-checked" data-rel="popover" data-placement="bottom"
              title="">删除选中</span>

        <div class="table-header">
            所有评论-的列表
        </div>

        <div class="table-responsive">
            <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                <thead>
                <tr>
                    <th class="center">
                        <label>
                            <input type="checkbox" class="ace-all"/>
                            <span class="lbl"></span>
                        </label>
                    </th>

                    <th>作者</th>
                    <th class="hidden-480">内容</th>

                    <th>
                        <i class="icon-time bigger-110 hidden-480"></i>
                        发布时间
                    </th>

                    <th class="hidden-480">对应文章</th>

                    <th class="hidden-480">状态</th>


                    <th></th>
                </tr>
                </thead>

                <tbody>

                {{foreach from=$list item=ls}}
                <tr class="c-{{$ls.id}}">
                    <td class="center">
                        <label>
                            <input type="checkbox" class="ace-checkbox" data-id="{{$ls.id}}"/>
                            <span class="lbl"></span>
                        </label>
                    </td>

                    <td>{{$ls.author}}</td>

                    <td>{{$ls.content}}</td>

                    <td class="hidden-480">{{$ls.publish_time}}</td>

                    <td><a href="/post/{{$ls.attach}}">{{$ls.attach_title}}</a></td>

                    <td class="hidden-480">
                        <span class="label label-sm label-warning">{{$ls.status}}</span>
                    </td>

                    <td>
                        <div class="visible-md visible-lg hidden-sm hidden-xs action-buttons">
                            <a class="blue" href="#">
                                <i class="icon-zoom-in bigger-130"></i>
                            </a>


                            <a class="red a-delete" href="javascript:;" data-id="{{$ls.id}}">
                                <i class="icon-trash bigger-130"></i>
                            </a>
                        </div>


                        <div class="visible-xs visible-sm hidden-md hidden-lg">
                            <div class="inline position-relative">
                                <button class="btn btn-minier btn-yellow dropdown-toggle" data-toggle="dropdown">
                                    <i class="icon-caret-down icon-only bigger-120"></i>
                                </button>

                                <ul class="dropdown-menu dropdown-only-icon dropdown-yellow pull-right dropdown-caret dropdown-close">
                                    <li>
                                        <a href="#" class="tooltip-info" data-rel="tooltip" title="View">
																				<span class="blue">
																					<i class="icon-zoom-in bigger-120"></i>
																				</span>
                                        </a>
                                    </li>

                                    <li>
                                        <a href="#" class="tooltip-success" data-rel="tooltip" title="Edit">
																				<span class="green">
																					<i class="icon-edit bigger-120"></i>
																				</span>
                                        </a>
                                    </li>

                                    <li>
                                        <a href="#" class="tooltip-error" data-rel="tooltip" title="Delete">
																				<span class="red">
																					<i class="icon-trash bigger-120"></i>
																				</span>
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </td>
                </tr>

                {{/foreach}}

                <script>
                    $(function () {
                        $("a.a-delete").click(function () {
                            var flag = true;
                            var id = $(this).attr('data-id');
                            if (flag) {
                                $.ajax({
                                    url: "/admin/index?p=comment&a=delete",
                                    data: {id: id},
                                    type: 'post',
                                    success: function (data) {
                                        data = $.parseJSON(data);
                                        if (data.msg == true) {
                                            alert("删除成功！");
                                            $(".c-" + id).remove();

                                        } else {
                                            alert("删除失败！" + data);
                                        }
                                    },
                                    error: function () {
                                        alert("发送请求失败！");
                                    }
                                })
                            }
//                                window.location.href = "/admin/index?p=post&a=delete&id="+id+"&backurl="+window.location.href;
                            else
                                return;
                        });

                        //删除选中
                        $(".delete-checked").click(function () {
                            var ck = $(".ace-checkbox");
                            var ids = '';
                            for (var i = 0; i < ck.length; i++) {
                                if (ck.eq(i).is(":checked")) {
                                    ids += ck.eq(i).attr("data-id")+',';
                                }
                            }
                            //alert(ids);
                            //return;

                            var flag = true;
                            if (flag) {
                                $.ajax({
                                    url: "/admin/index?p=comment&a=d",
                                    data: {id: ids},
                                    type: 'post',
                                    success: function (data) {
                                        data = $.parseJSON(data);
                                        if (data.msg == true) {
                                            alert("删除成功!");
                                            var arr = ids.split(',');
                                            for (i = 0; i < arr.length; i++) {
                                                $(".c-" + arr[i]).remove();
                                            }
                                        } else {
                                            alert("删除失败！");
                                        }
                                    },
                                    error: function () {
                                        alert("发送请求失败！");
                                    }

                                })
                            }
                        })
                    })
                </script>


                </tbody>
            </table>
        </div>
    </div>
</div>
{{/block}}